<!--
 * @FilePath     : /study_code/layui/15-24.html
 * @Description  : 远程分页
 * @Date         : 2025-04-09 15:50:51
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-09 16:20:48
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="demo1" class="xm-select-demo"></div>

    <script src="/xm-select/dist/xm-select.js"></script>
    <script src="/axios/axios.min.js"></script>
    <script>
      /*
      // 语法
      xmSelect.render({
          //...
        //开启分页
          paging: true,
        //远程分页
          pageRemote: true,
        //实现方法
          remoteMethod: function(val, cb, show, pageIndex),
      })
      */

      var demo1 = xmSelect.render({
        el: '.xm-select-demo',

        //
        paging: true, // 前提
        pageRemote: true, // 开启远程分页
        remoteMethod: function (val, cb, show, pageIndex) {
          console.log(1, '搜索框的内容, 不开启搜索默认为空', val)
          console.log(2, '回调函数', cb)
          console.log(3, '当前下拉框是否展开', show)
          console.log(4, '当前第几页', pageIndex)

          // 请求获取数据
          axios({
            method: 'GET',
            url: '/layui/xm-selects/remote-search1',
            params: {
              keyword: val + '_' + pageIndex,
            },
          })
            .then(res => {
              console.log('远程数据-成功', res)
              const {code, data, msg} = res.data
              cb(data, 4)
            })
            .catch(err => {
              console.log('远程数据-失败', err)
              alert('远程数据获取失败')
              cb([], 0)
            })
        },
      })
    </script>
  </body>
</html>
